<template>
  <div class="giftList">
    <!-- 搜索 -->
    <div class="section">
      <h3>转游礼包列表</h3>
      <search-item
        @searchList="searchData"
        :giftType="2"
      ></search-item>
    </div>
    <!-- 表格 -->
    <el-table
      :height="tabHeight"
      border
      style="width: 99%"
      align="center"
      :data="tableData"
      v-loading="loading"
    >
      <el-table-column
        prop="title"
        label="礼包名称"
        width="100"
      ></el-table-column>
      <el-table-column label="关联游戏">
        <template slot-scope="scope">
          <img
            :src="scope.row.icon"
            alt
            v-if="scope.row.icon != ''"
            style="width: 44px; height: 44px; margin: 0 auto; display: block"
          />
          <span class="gamename">{{ scope.row.game_name }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="礼包类型"
        width="120"
      >
      <template>
          <span>转游礼包</span>
      </template>
      </el-table-column>
      <el-table-column prop="content" label="礼包内容"></el-table-column>
      <el-table-column prop="use_desc" label="使用方法"></el-table-column>
      <el-table-column label="礼包剩余" width="150">
        <template slot-scope="scope">
          <div
            v-if="scope.row.status == 1"
            style="color: #f00; display: inline-block; width: 80px"
          >
            <span>{{ scope.row.remain }}</span
            >/
            <span>{{ scope.row.total }}</span>
          </div>
          <div v-else style="display: inline-block; width: 80px">
            <span>{{ scope.row.remain }}</span
            >/
            <span>{{ scope.row.total }}</span>
          </div>
          <el-button type="text" size="small" @click="showaddCode(scope.row)"
            >补仓</el-button
          >
        </template>
      </el-table-column>
      <el-table-column
        label="金额统计时间"
        prop="paytime"
        width="170"
      ></el-table-column>
      <el-table-column prop="create_time" label="创建时间"></el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small" style="color: #d7dae2"
            >编辑</el-button
          >
          <el-button type="text" size="small" style="color: #d7dae2"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="bottom">
      <!-- 将分页器作为子组件引入 -->
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="pagenationData.currentPage"
        :page-size="pagenationData.pageSize"
        :total="pagenationData.pageTotal"
        background
        layout="prev, pager, next"
        prev-text="上一页"
        next-text="下一页"
      ></el-pagination>
    </div>
    <!-- 补仓 -->
    <TransferEditCode
      v-if="addcodedialog.show"
      :isShow="addcodedialog.show"
      :dialogRow="addcodedialog.dialogRow"
      @closeDialog="hideaddcodeDialog"
    ></TransferEditCode>
  </div>
</template>
<script>
import SearchItem from "./component/searchItem";
import TransferEditCode from "./component/transferEditCode";

import { transferGiftList } from "@/api/giftManage";
export default {
  name: "transferGiftList",
  inject: ["reload"],
  data() {
    return {
      tabHeight: window.innerHeight - 230,
      tableData: [],
      search: {},
      loading: true,
      pagenationData: {
        pageTotal: 0,
        currentPage: 1,
        pageSize: 20,
      },
      pageData: {
        page: 1,
        limit: 20,
      },

      addcodedialog: {
        show: false,
        dialogRow: {},
      },
    };
  },
  components: {
    SearchItem,
    TransferEditCode,
  },
  mounted() {
    this.transferGiftList();
  },
  methods: {
    searchData(search) {
      this.search = search;
      this.search.page = 1;
      this.pagenationData.currentPage = 1;
      this.searchList();
    },
    // 搜索数据
    searchList() {
      this.loading = true;
      const para = Object.assign({}, this.search);
      transferGiftList(para)
        .then((res) => {
          this.loading = false;
          this.pagenationData.pageTotal = res.data.count;
          this.tableData = res.data.list;
        })
        .catch((error) => {});
    },
    // 获取数据列表
    transferGiftList() {
      const para = Object.assign({}, this.pageData);
      transferGiftList(para)
        .then((res) => {
          this.loading = false;
          this.pagenationData.pageTotal = res.data.count;
          this.tableData = res.data.list;
        })
        .catch((error) => {});
    },
    handleCurrentChange(val) {
      this.pageData.page = val;
      this.search.page = val;
      this.searchList();
    },
    showaddCode(row) {
      this.addcodedialog.dialogRow = row;
      this.addcodedialog.show = true;
    },
    hideaddcodeDialog() {
      this.addcodedialog.show = false;
    },
  }
};
</script>
<style lang="scss">
.giftList {
  .gamename {
    width: 150px;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .section {
    justify-content: flex-start;
  }
}
.el-message-box__content {
  font-size: 13px;
}
.el-table th div {
  line-height: 23px;
}
.el-message-box__title,
.el-message-box__btns {
  text-align: center;
}
.el-message-box .el-button--small {
  padding: 9px 30px;
}
.el-message-box {
  padding: 20px 0;
}
.el-message-box__content {
  padding: 25px;
}
.el-table__row {
  .el-table_1_column_2 {
    text-align: left;
  }
}
</style>